@extends('layouts.header')
@section('style')
    .radio-box {
    padding-left: 18px;
    padding-right: 0px;
    padding-top: 0px;
    padding-bottom: 0px;
    }

    tbody tr:hover {
    cursor: pointer;
    /*background-color: #9bf5f5;*/
    }
    th,td{
    white-space:nowrap;
    }

    .trChecked {
    background-color: #9bf5f5;
    }

    #gqj_ID_head {
    text-align: right;
    }

    #gqj_ID {
    text-align: center;
    }
@endsection
@section('content')
    @php
        $agent = new Jenssegers\Agent\Agent();
        $isphone = $agent->isPhone();
    @endphp
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
        检测业务 <span class="c-gray en">&gt;</span>
        <a href="javascript:;"
           onclick="location.href='/{{config('constant.name_admin')}}/contract/indexInfoLuru';">信息录入</a><span
                class="c-gray en">&gt;</span>
        点击进入【{{ $contractInfo->client_name }}】 <a class="btn btn-primary radius r"
                                                  style="line-height:1.6em;margin-top:3px"
                                                  href="javascript:location.reload();" title="刷新"><i
                    class="Hui-iconfont">&#xe68f;</i></a>
        <a class="btn btn-primary radius r mr-10" style="line-height:1.6em;margin-top:3px"
           href="/{{config('constant.name_admin')}}/contract/indexInfoLuru"> <i
                    class="Hui-iconfont Hui-iconfont-arrow1-left"></i>&nbsp;&nbsp;返回 </a>
    </nav>
    <ul class="Huifold page-container " id="Huifold" style="border: none;">
        <li class="item panel panel-primary ">
            <h4 class="panel-header" style="background-color:#5a98de;">信息录入区
                @if($isphone)
                    <span class="f-r">
                <a class="btn radius" href="javascript:location.replace(location.href);"
                   title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
            </span>
                @endif
                <b style="color: #fff;">+</b>
            </h4>
            <div class="info">
                <form class="form form-horizontal" id="form" autocomplete="off">
                    {{ csrf_form_field() }}
                    <input type="hidden" name="detail_id" value="0">
                    <input type="text" hidden name="photo" value="">
                    <div class="row cl">
                        <label class="form-label col-sm-1">条形码：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="" placeholder="" name="bar_code" disabled>
                        </div>
                        @if($isphone)
                            <br><br>
                        @endif
                        <label class="form-label col-sm-1">样品名称：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="" placeholder="" name="tool_name" disabled>
                        </div>
                        @if($isphone)
                            <br><br>
                        @endif
                        <label class="form-label col-sm-1">样品自编号：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="{{old('self_num')}}" placeholder=""
                                   name="self_num" id="self_num">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">规格型号：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="{{old('guige_xinghao')}}" placeholder=""
                                   name="guige_xinghao" id="guige_xinghao">
                        </div>
                        @if($isphone)
                            <br><br>
                        @endif
                        <label class="form-label col-sm-1">商标：</label>
                        <div class="formControls col-sm-2">
                            <input type="text" class="input-text" value="{{old('brand')}}" placeholder="" name="brand"
                                   id="brand">
                        </div>
                        @if($isphone)
                            <br><br>
                        @endif
                        <label class="form-label col-sm-1">生产厂家：</label>
                        <div class="formControls col-sm-2">
                            <select class="select2" id="facturer" style="width: 100%">
                                <option value="">--请选择--</option>
                                @foreach ($factorys as $val)
                                    <option value="{{ $val }}"
                                            @if(old('manufacturer') === $val) selected @endif> {{ $val }} </option>
                                @endforeach
                            </select>
                        </div>
                        <div class="formControls col-sm-2">
                            <input type="text" class="input-text" value="{{old('manufacturer')}}"
                                   placeholder="这里可以填写生产厂家"
                                   name="manufacturer" id="manufacturer">
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">生产日期：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" id="production_date" name="production_date"
                                   value="{{old('production_date')}}" class="input-text">
                        </div>
                        @if($isphone)
                            <br><br>
                        @endif
                        <label class="form-label col-sm-1">样品状态：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text" value="外观无异常" placeholder="" name="sample_status"
                                   id="sample_status">
                        </div>
                        @if($isphone)
                            <br><br>
                        @endif
                        <label class="form-label col-sm-1">原始条码：</label>
                        <div class="formControls col-sm-3">
                            <input type="text" class="input-text " value="" name="bar_code_1st" id="bar_code_1st"
                                   disabled>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-sm-1">检测地点：</label>
                        <div class="formControls col-sm-11" id="place">
                            @if($places)
                                @foreach($places as $i => $item)
                                    <div class="radio-box">
                                        <input @if($i===0) checked @endif name="place" id="radio-{{$i}}" type="radio"
                                               value="{{$item}}">
                                        {{-- <label for="radio-{{$i}}">{{$item}}</label>--}}
                                        <span for="radio-{{$i}}">{{$item}}</span>
                                        <i onclick="test_place_op('del','{{$item}}','radio-{{$i}}')"
                                           class="Hui-iconfont">&#xe6e2;</i>
                                    </div>
                                @endforeach
                            @endif
                            <div class="radio-box">
                                <input name="place" id="ziding" type="radio" value="">
                                <span for="ziding">自定义检测地点：
                                    <input onclick="check()" id="test_place" class="inline input-text " maxlength="9"
                                           type="text" placeholder="自定义检测地点">
                                    <input onclick="test_place_op('add')" id="test_place_add"
                                           class="btn btn-primary-outline hidden" type="button" value="添加到地点列表">
                                    <span style="color: red;">*</span>最长9个汉字或数字
                                </span>
                            </div>
                        </div>
                    </div>
                    @csrf
                    <input type="hidden" name="is_scan" value="0">
                    @if ($enable_tool_ID)
                        @if($isphone)
                            <br><br>
                        @endif
                        <div class="form form-horizontal">
                            <div class="row cl">
                                <label class="form-label col-sm-1">工器具ID：</label>
                                <div class="formControls col-sm-4">
                                    @if($setSys['gqjID_count'] == 24)
                                        <input type="text" class="input-text disabled"
                                               value="{{$setSys['gqj_com_code']}}" placeholder="" id="gqj_com_code"
                                               style="width: 10%" readonly>
                                        <input type="text" class="input-text disabled" value="{{$setSys['gqj_scode']}}"
                                               placeholder="" id="gqj_scode" style="width: 7%" readonly>
                                    @endif
                                    <input type="text" class="input-text disabled" value="" placeholder=""
                                           name="gqj_ID_head" id="gqj_ID_head" style="width: 25%" readonly>
                                    <input type="text" class="input-text" value="" placeholder="" name="gqj_ID"
                                           id="gqj_ID" style="width: 13%">
                                    @if($gqjID_18_pro['sub_count'])
                                        <input type="text" class="input-text" value="" placeholder="" name="gqj_ID_foot"
                                               id="gqj_ID_foot" style="width: 8%">
                                    @endif
                                    @if($setSys['gqjID_count'] == 24)
                                        <input type="text" class="input-text disabled" value="" placeholder=""
                                               name="gqjID_check" id="gqjID_check" style="width: 5%" readonly title="">
                                    @endif
                                    <a class="btn btn-primary radius size-S"
                                       href="/{{config('constant.name_admin')}}/setting/edit?index=1">编辑</a>
                                </div>
                                最近一次提交的工器具ID： <span id="lastId"></span>
                            </div>
                        </div>
                    @endif
                    <div class="form form-horizontal ">
                        <div class="row cl">
                            <label class="form-label col-sm-1">强制报废日期：</label>
                            <div class="formControls col-sm-3">
                                <input type="text" id="force_scrap_date" name="force_scrap_date" value=""
                                       onfocus="WdatePicker({minDate:'%y-%M-%d'})" class="input-text Wdate">
                            </div>
                            @if(config('constant.app_name') === 'ChongQingYuDian')
                                <label class="form-label col-sm-1">内网ID：</label>
                                <div class="formControls col-sm-3">
                                    <input type="text" class="input-text" value="" placeholder="" name="third_id"
                                           id="third_id">
                                </div>
                            @endif
                            @if(config('constant.app_name') === 'GUIZHOUSONGBIANDIAN')
                                <label class="form-label col-sm-1">报告编号：</label>
                                <div class="formControls col-sm-3">
                                    <input type="text" class="input-text" value="" placeholder="自定义内网编号"
                                           name="batch_num_custom" id="batch_num_custom">
                                </div>
                            @endif
                        </div>
                    </div>
                    <div class="form form-horizontal ">
                        <div class="row cl">
                            <label class="form-label col-sm-1">其他参数：</label>
                            <div class="formControls col-sm-3">
                                <input type="text" id="force_scrap_date" name="force_scrap_date" value=""
                                       onfocus="WdatePicker({minDate:'%y-%M-%d'})" class="input-text Wdate">
                            </div>
                            @if(config('constant.app_name') === 'ChongQingYuDian')
                                <label class="form-label col-sm-1">内网ID：</label>
                                <div class="formControls col-sm-3">
                                    <input type="text" class="input-text" value="" placeholder="" name="third_id"
                                           id="third_id">
                                </div>
                            @endif
                            @if(config('constant.app_name') === 'GUIZHOUSONGBIANDIAN')
                                <label class="form-label col-sm-1">报告编号：</label>
                                <div class="formControls col-sm-3">
                                    <input type="text" class="input-text" value="" placeholder="自定义内网编号"
                                           name="batch_num_custom" id="batch_num_custom">
                                </div>
                            @endif
                        </div>
                    </div>
                </form>
                <div class="form form-horizontal" id="forphoto" hidden>
                    <div class="row cl">
                        <label class="form-label col-sm-1">铭牌照片：</label>
                        <div class="formControls col-sm-11">
                            <span class="btn-upload"> <a href="javascript:;"
                                                         class="btn btn-primary radius btn-upload"><i
                                            class="Hui-iconfont"></i> 浏览文件</a>
                               <input type="file" multiple="" name="file_0" class="input-file" accept="image/*"
                                      id="changeMore">
                           </span>
                            <div class="mt-5">
                                <span style='color:red;'>要求：</span>图片宽高比为4:3或3:4（建议直接用手机拍摄4:3图片，如果需要再用imark或小Q画笔对图片进行局部放大）
                            </div>
                            <div class="mt-5" id="ImgConDiv">
                                <img onclick="biggerimg(this)" class="img-responsive radius" alt="" id="ImgCon"
                                     style="width: 150px;">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form form-horizontal">
                    <div class="row cl">
                        <label class="form-label col-sm-1">扫码：</label>
                        <div class="formControls col-sm-4">
                            <input type="text" class="input-text" value="" placeholder="扫描ID码或合格证上的二维码读取基本信息"
                                   id="erweima" autocomplete="off" disabled>
                        </div>
                        @if(config('constant.app_name') === 'HuiBangJianCe' || config('constant.app_name') === 'CeShi')
                            <div class="formControls col-sm-1">
                                <a class="btn btn-primary-outline radius" onclick="scanCode()">微信扫码</a>
                            </div>
                        @endif
                    </div>
                </div>
                <div class="form form-horizontal text-c">
                    <div class="mt-15">
                        <input class="btn btn-primary radius" type="submit" form="form"
                               value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                        <a class="btn btn-primary radius ml-20" onclick="next(this)">下一个</a>
                    </div>
                </div>
            </div>
        </li>
        <div class="panel panel-primary mt-10">
            <div class="panel-header">样品列表区</div>
            <div class="panel-body">
                <div class="cl pd-5 bg-1 bk-gray">
                    {{--                <span class="l">--}}
                    {{--                    <a class="btn btn-primary radius" href="javascript:;" onclick="add('添加客户','/{{config('constant.name_admin')}}/client/add','800','400')"><i class="Hui-iconfont">&#xe600;</i> 添加客户</a>--}}
                    {{--                </span>--}}
                    @foreach($gaiyao as $item)
                        <span class="ml-10 myFenList"><span class="tool-name">{{$item->tool_name}}</span>({{$item->count}})</span>
                    @endforeach
                </div>
                <div class="mt-10">
                    <table class="table table-border table-bordered table-bg table-hover table-condensed table-responsive"
                           id="datatb">
                        <thead>
                        <tr class="text-c">
                            <th><input type="checkbox" onclick="checkAll(this)"></th>
                            <th>铭牌照片</th>
                            <th>条形码</th>
                            <th>原始条码</th>
                            <th>样品名称</th>
                            <th>额定电压</th>
                            <th>分类</th>
                            <th>样品自编号</th>
                            <th>规格型号</th>
                            <th>商标</th>
                            <th>生产厂家</th>
                            <th>生产日期</th>
                            <th>强制报废日期</th>
                            <th>样品状态</th>
                            <th>检测地点</th>
                            <th class="{{ $enable_tool_ID ? '' : 'hidden'}}">工器具ID</th>
                            <th>内网ID</th>
                            <th class="@if(config('constant.app_name') !== 'GUIZHOUSONGBIANDIAN') hidden @endif">报告编号
                            </th>
                        </tr>
                        </thead>
                    </table>
                    <div style="clear:both"></div>
                </div>
            </div>
        </div>
    </ul>

    <script type="text/javascript" src="/admin/lib/jquery.mousewheel.min.js"></script>

    <script type="text/javascript"
            src="/admin/static/myfolder/js/imgopreate.js?ver={{config('constant.static_res_ver')}}"></script>
    @if(!config('constant.is_lan'))
        <script type="text/javascript" src="//res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
        <script type="text/javascript" src="/admin/static/myfolder/js/wxjssdk.js"></script>
    @endif

    <script type="text/javascript">
        var table,
            index2,
            isphone = '{{$isphone}}';
        $(function () {
            $('.select2').select2();

            $('#lastId').text(localStorage.getItem('indexInfoLuru-lastGqjId'));

            if (isphone) {
                $('label').removeClass('col-sm-1').addClass('col-xs-4').css('display', 'inline-block').css('text-align', 'right');
                $('label').siblings('div').not('#place').removeClass('col-sm-4').addClass('col-xs-7');
            }
            $("#Huifold").Huifold({
                titCell: '.item h4',
                mainCell: '.item .info',
                type: 0,
                trigger: 'click',
                className: "selected",
                speed: 0
            });
            $("#Huifold li").first().find('h4').trigger("click");

            getInfoByErweima();//扫描二维码获取样品的基本信息

            $("#form").validate({
                success: "valid",
                submitHandler: function (form) {
                    $(form).ajaxSubmit({
                        type: 'post',
                        url: "",//自己提交给自己可以不写url
                        data: {},
                        beforeSerialize: function () {
                            let str = '';
                            $(':input:text', '#form').map(function (index, el) {
                                str += $(el).val();
                            })
                            if (str === '') {
                                layer.msg('请先编辑要修改的数据');
                                return false;
                            }
                            // 检查是否有多选值
                            var checkels = $("input:checkbox[name='check']:checked").map(function (index, elem) {
                                return $(elem).val();
                            }).get().join(',');
                            if (checkels !== '') {
                                $("input[name='detail_id']").val(checkels);
                            }
                        },
                        //beforeSend  beforeSubmit
                        beforeSubmit: function () {
                            //如果验证不通过，返回false，阻止表单提交
                        },
                        beforeSend: function () {
                            //0.4透明度 白色遮罩
                            index2 = layer.load(2, {shade: [0.3, '#fff']});
                        },
                        complete: function () {
                            layer.close(index2);
                        },
                        success: function (data) {
                            //添加id码重复提醒
                            if (data.code !== undefined) {
                                layer.msg(data.msg, {icon: data.code, time: 1000});
                                return false;
                            }
                            //判断添加结果
                            if (data == '1') {
                                let gqjIDfoot = $("[name='gqj_ID_foot']").val();
                                let lastId = $("[name='gqj_ID_head']").val() + $("[name='gqj_ID']").val() + (gqjIDfoot == undefined ? '' : gqjIDfoot);
                                localStorage.setItem('indexInfoLuru-lastGqjId', lastId);
                                $('#lastId').text(lastId);
                                table_reload(0);//0停留在当前页，1回到第一页
                                layer.msg('操作成功!', {icon: 1, time: 1000});
                                $('#somepush').addClass('hidden');
                                setTimeout(function () {
                                    window.location.reload()
                                }, 2000)
                            } else {
                                layer.msg('未修改数据!', {icon: 2, time: 2000});
                                setTimeout(function () {
                                    window.location.reload()
                                }, 2000)
                            }
                        },
                        error: function (data) {
                            ajax_error(data);
                        }
                    });
                }
            });

            $.fn.dataTable.ext.errMode = 'throw';//datatable抛异常的方式，在console中输出，默认以alert的方式弹出
            table = $('#datatb').DataTable({
                ajax: "{{URL::full()}}",
                scrollX: true,
                autoWidth: true,
                searching:false,
                language: {url: '/admin/lib/datatables/dataTables_Chinese_Lang.json'},
                initComplete: function (settings, json) {
                    //当表格完成加载绘制完成后执行此方法
                    //仅初次表格数据加载完成后执行
                    // $(row).addClass( 'text-c' );
                    $('#datatb_filter label input').attr('placeholder', '条形码/名称/工器具ID')
                },
                columns: [
                    {
                        data: "null", class: "text-c",
                        render: function (data, type, row, meta) {
                            return '<input type="checkbox" name="check" value="' + row.id + '"/>';
                        }, searchable: false, orderable: false
                    },
                    {
                        data: "photo", class: "text-c photo", render: function (data, type, row, meta) {
                            if (data === '') {
                                return '';
                            }
                            data += '?t=' + new Date();
                            return '<div><img class="img-responsive" src="' + data + '" />' +
                                '<a onclick="imgdel(' + row.bar_code + ',this)" class="btn btn-danger-outline btn-block radius size-MINI mt-5">删除</a>' +
                                '</div>';
                        }
                    },
                    {
                        data: "bar_code", class: "text-c bar_code",
                        render: function (data, type, row, meta) {
                            return '<span data-id="' + row.id + '">' + data + '</span>';
                        }
                    },
                    {data: "bar_code_1st", class: "text-c bar_code_1st"},
                    {data: 'tool_name', class: "text-c tool_name"},
                    {data: 'voltage', class: "text-c voltage"},
                    {data: 'class', class: "text-c class"},
                    {data: "self_num", class: "text-c self_num"},
                    {data: "guige_xinghao", class: "text-c guige_xinghao"},
                    {data: "brand", class: "text-c brand"},
                    {data: "manufacturer", class: "text-c manufacturer"},
                    {data: "production_date", class: "text-c production_date"},
                    {
                        data: "force_scrap_date",
                        class: "text-c force_scrap_date",
                        render: function (data, type, row, meta) {
                            return row.is_luru == 1 ? (data ? data : '/') : '';
                        }
                    },
                    {data: "sample_status", class: "text-c sample_status"},
                    {data: "place", class: "text-c place"},
                    {data: "gqj_ID", class: "text-c gqj_ID {{ $enable_tool_ID ? '' : 'hidden'}} "},
                    {
                        data: "third_id",
                        class: "text-c third_id"
                    },
                    {
                        data: "batch_num_custom",
                        class: "text-c batch_num_custom {{config('constant.app_name') === 'GUIZHOUSONGBIANDIAN' ? '' : 'hidden'}}"
                    }
                ],
            })

            /*  draw  在表格完成绘制后触发*/
            table.on('draw', function () {
                table.columns.adjust();
                /*var info = table.page.info();
                //如果最后一页仅剩一条记录，而且不是在第一页
                if((info.start == info.end) && info.end > 1){
                    //跳转到上一页
                    $('#datatable_previous').click();
                } */
                $("tbody tr","#datatb").click(function () {
                    localStorage.setItem('indexInfoLuru-last-click-id', $(this).find("td.bar_code span").attr('data-id'));
                    let length = $("input:checkbox[name='check']:checked").length;
                    if (length > 0) {
                        resetcheckbox();
                        return;
                    }
                    $("tbody tr").removeClass('trChecked');
                    $(this).addClass('trChecked');

                    var bar_code = $(this).find("td.bar_code span").text();
                    $("[name='bar_code']").val(bar_code);

                    var bar_code_1st = $(this).find("td.bar_code_1st").text();
                    $("[name='bar_code_1st']").val(bar_code_1st);

                    var detail_id = $(this).find("td.bar_code span").attr('data-id');
                    $("[name='detail_id']").val(detail_id);

                    var tool_name = $(this).find("td.tool_name").text();
                    $("[name='tool_name']").val(tool_name);
                    if (tool_name.indexOf('斗臂车') > -1) {
                        $('#forphoto').show();
                    } else {
                        $('#forphoto').hide();
                    }
                    var place = $(this).find("td.place").text();
                    if (place) {
                        $('input[name=place]').val(place).trigger('click');
                        $('#test_place').val(place).trigger('click');
                    }
                    var photo = $(this).find("td.photo > div").html();
                    $("#ImgCon").attr('src', photo ? $(photo).attr('src') : '');

                    $("input[type='submit']").removeClass("disabled").val('提交');
                    $('#erweima').removeAttr("disabled");

                    get_form_td(this, 'self_num');
                    get_form_td(this, 'class');
                    get_form_td(this, 'voltage');
                    get_form_td(this, 'guige_xinghao');
                    get_form_td(this, 'brand');
                    get_form_td(this, 'manufacturer');
                    get_form_td(this, 'production_date');
                    get_form_td(this, 'third_id');
                    get_form_td(this, 'batch_num_custom');
                    get_form_td(this, 'force_scrap_date');
                    // get_form_td(this,'sample_status');
                    $("[name='sample_status']").val('外观无异常');

                    //-----------------------------------
                    $('#gqj_ID_head').val('');
                    $('#gqj_ID').val('');
                    $('#gqj_ID_foot').val('');

                    var x = $(this).find("td.gqj_ID").text();
                    if (x.trim() != '') {
                        let gqj_com_code = '{{$setSys["gqj_com_code"]}}',
                            comcodeLen = gqj_com_code.length,
                            gqj_scode = '{{$setSys["gqj_scode"]}}',
                            scodeLen = gqj_scode.length,
                            start = 0, end;
                        if (x.length == 24) {
                            start += (comcodeLen + scodeLen);
                        }
                        $("[name='gqj_ID_head']").val(x.substr(start, 13));
                        start += 13;
                        $("[name='gqj_ID']").val(x.substr(start, parseInt('{{$gqjID_18_pro['serial']}}')));
                        start += end;
                        if ({{$gqjID_18_pro['sub_count']}}) {
                            $("[name='gqj_ID_foot']").val(x.substr(start, 2));
                        }
                        if (x.length == 24) {
                            console.log(x);
                            $("[name='gqjID_check']").val(x.substr(-1));
                            $("[name='gqjID_check']").attr('title', x.substr(-1));
                        }
                    } else {
                        if ({{$enable_tool_ID}}) {
                            generate_gqjID(detail_id);//生成工器具ID
                        }
                    }

                    //----------------------------
                    //去除平板或手机focus引起的呼出键盘
                    $('#erweima').val('').attr('readonly', true).focus();
                    setTimeout(function () {
                        $('#erweima').attr('readonly', false)
                    }, 50)
                    // $("html,body").animate({scrollTop: $('#datatable').offset().top}, 0);  //将页面定位到样品列表\
                });
                if ($("tbody tr", '#datatb').eq(0).find("td.self_num").text() === '' || $("tbody tr", '#datatb').eq(0).find("td.gqj_ID").text() === '') {
                    $("tbody tr", '#datatb').eq(0).trigger('click');
                } else {
                    let id = localStorage.getItem('indexInfoLuru-last-click-id');
                    $("span[data-id='" + id + "']").trigger('click');
                }
            });
        });


        /* 扫描二维码获取样品的基本信息 */
        var scanFlag = false;

        function getInfoByErweima() {
            $('#erweima').keypress(function (event) {
                // if(event.which >= 65 && event.which <= 90){
                // msg = '你按下了 ' + String.fromCharCode(event.which);
                // layer.msg(msg,{ time:2000 });
                // }
                if (event.which == 13) {
                    // msg = '你按下了 回车';
                    // layer.msg(msg,{ time:2000 });
                    var input_val = $(this).val();
                    keyenter(input_val);
                    //点击第一个tr
                } else {
                    if (scanFlag) {
                        $(this).val('');
                        scanFlag = false;
                    }
                }
            });
        }

        function keyenter(input_val) {
            if (input_val.length > 0) {
                //indexOf() 方法对大小写敏感！
                //indexOf() 如果要检索的字符串值没有出现，则该方法返回 -1。
                var start_index = input_val.indexOf('?id=');//获得字符串的开始位置
                let id = '';
                if (start_index == -1) {
                    if (input_val.length > 17) {
                        id = input_val.substring(input_val.length - 18);
                    } else {
                        layer.msg('二维码不合法，切换到英文输入法试试吧！', {time: 2000});
                    }
                } else {
                    id = input_val.substr(start_index + 4);
                }
                if (id == '') {
                    layer.msg('二维码不合法', {time: 2000});
                    return false;
                }
                // var str_res = input_val.substr(start_index);
                // layer.msg(id,{ time:2000 });
                var index2;
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/sampleInfo/getInfoById' + '?id=' + id,
                    // dataType: 'json',
                    success: function (data) {
                        // console.log(data);
                        if (data === 'false') {
                            layer.msg('未查到记录!', {time: 2000});
                        } else {
                            for (var i in data) {
                                // var item = data[i];
                                $("[name='" + i + "']").val(data[i]);
                            }
                            let x = data['gqj_ID'];
                            if (x) {
                                $("[name='gqj_ID_head']").val(x.substr(0, 13));
                                $("[name='gqj_ID']").val(x.substr(13, 3));
                                $("[name='gqj_ID_foot']").val(x.substr(16, 2));
                            }
                            $("[name='is_scan']").val(1);
                            $("#sample_status").val('外观无异常');
                            layer.msg('查询成功,正在提交！', {icon: 1, time: 2000});
                            $('#form').submit();
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.05, '#000']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });

            }

            scanFlag = true;
        }

        /* 获取表格的td值 */
        function get_form_td(obj, str) {
            var x = $(obj).find("td." + str).text();
            if (x != '') {
                $("[name='" + str + "']").val(x);
            } else {
                $("[name='" + str + "']").val('/');
            }
        }

        /*表格重新加载*/
        function table_reload(bool) {
            $("input[name='detail_id']").val('');
            $('input[type=submit]').addClass('disabled')
            $("#datatb").find("thead").find("input[type=checkbox]").removeAttr('checked');  //清除表头 CheckBox的对勾
            if (bool) {
                //true时，跳到第一页
                table.ajax.reload();
            } else {
                //false时，停留在原来页
                table.ajax.reload(null, false);
            }
        }

        /*生成工器具ID*/
        function generate_gqjID(id) {
            var index2;
            $.ajax({
                type: 'GET',
                url: '/{{config('constant.name_admin')}}/sampleInfo/generateGqjID' + '?id=' + id,
                // dataType: 'json',
                success: function (data) {
                    // console.log(data);
                    $('#gqj_ID_head').val(data.head);
                    $('#gqj_ID').val(data.body);
                    $('#gqj_ID_foot').val(data.foot);
                    $('#gqjID_check').val(data.gqjID_check);
                    $('#gqjID_check').attr('title', data.gqjID_check);
                },
                error: function (data) {
                    ajax_error(data);
                },
                beforeSend: function () {
                    //0.4透明度 白色遮罩
                    index2 = layer.load(2, {shade: [0.05, '#000']});
                },
                complete: function () {
                    layer.close(index2);
                },
            });
        }

        /*编辑*/
        function edit(title, url, id, w, h) {
            layer_show(title, url + '?id=' + id, w, h);
        }

        /*添加*/
        function add(title, url, w, h) {
            layer_show(title, url, w, h);
        }

        function resetcheckbox() {
            $('input[type=submit]').removeClass('disabled').val('批量提交');
            // $(':input','#form').not(':button, :submit, :reset').val('').removeAttr('checked').removeAttr('selected');
            // $(':input[type=text]','#form').val('').removeAttr('checked').removeAttr('selected');  //清空所有input框
            //清空条形码，样品名称，工器具id
            $(':input:disabled', '#form').val('');
            $(':input[name=gqj_ID_head]', '#form').val('');
            $(':input[name=gqj_ID]', '#form').val('');
            $(':input[name=gqj_ID_foot]', '#form').val('');
            $(':input[name=photo]', '#form').val('');
            $('#forphoto').hide();
        }

        //铭牌照片
        $("#changeMore").click(function (e) {
            let id = $('input[name=bar_code]').val();  //将文件命名为当前编码
            if (id == 0) {
                layer.alert('请先选择斗臂车');
                return false;
            }
            $(this).change(function (e) {
                var file = e.target.files[0],//拿到原始对象
                    thisType = file.type,//获取到表面的名称，可判断文件类型
                    reader = new FileReader();
                if (thisType.indexOf('image') !== 0) {
                    layer.alert('该文件不是图片！');
                    return false;
                }
                if (file.size > 500 * 1024) {
                    //调用函数,对图片进行压缩
                    compressimg(file, function (imgBase64) {
                        $('input[name=photo]').val(imgBase64);
                        $('#ImgCon').attr('src', imgBase64).load(function () {/*如果要获取图片的真实的宽度和高度有三点必须注意1、需要创建一个image对象：如这里的$("")2、指定图片的src路径3、一定要在图片加载完成后执行如.load()函数里执行*/
                            let realWidth = this.width, realHeight = this.height,
                                bili = (realHeight / realWidth).toFixed(2);//如果真实的宽度大于浏览器的宽度就按照100%显示
                            if ((bili < 0.77 && bili > 0.73) || (bili < 1.35 && bili > 1.31)) {
                            } else {
                                $(this).attr('src', '');
                                layer.msg('图片不符合要求');
                                return false;
                            }
                        });
                    })
                }
                //readAsDataURL(file),读取文件，将文件以数据URL的形式保存在result的属性中
                reader.readAsDataURL(file);
                //文件加载成功以后，渲染到页面
                reader.onload = function (e) {
                    let img = document.createElement('img');
                    $(img).attr("src", e.target.result).load(function () {/*如果要获取图片的真实的宽度和高度有三点必须注意1、需要创建一个image对象：如这里的$("")2、指定图片的src路径3、一定要在图片加载完成后执行如.load()函数里执行*/
                        let realWidth = this.width, realHeight = this.height,
                            bili = (realHeight / realWidth).toFixed(2);//如果真实的宽度大于浏览器的宽度就按照100%显示
                        if ((bili < 0.77 && bili > 0.73) || (bili < 1.35 && bili > 1.31)) {
                            $('#ImgCon').attr('src', e.target.result);
                            $('input[name=photo]').val(e.target.result);
                        } else {
                            layer.msg('图片不符合要求');
                            return false;
                        }
                    });
                }
            })

        });
        $('#test_place').bind('input propertychange', function () {
            let val = $(this).val();
            if (val) {
                $("#test_place_add").removeClass('hidden');
                $("input[type='radio']:checked", '#place').val(val);
            }
            val ? $("#test_place_add").removeClass('hidden') : $("#test_place_add").addClass('hidden');
        })

        function test_place_op(func = 'add', val = '', id = '') {
            val = func === 'add' ? $('#test_place').val() : val;
            if ($.trim(val) !== '') {
                $.ajax({
                    type: 'GET',
                    url: '/{{config('constant.name_admin')}}/setting/testPlace/' + func + '/' + val,
                    success: function (res) {
                        let str = func === 'add' ? '添加' : '删除';
                        if (res === '1') {
                            layer.msg(str + '成功');
                            if (func === 'add') {
                                str = '<div class="radio-box">\n' +
                                    '                                    <input name="place" id="radio-{{time()}}" type="radio" value="' + val + '">\n' +
                                    '                                    <label for="radio-{{time()}}">' + val + '</label>\n' +
                                    '                                    <i onclick="test_place_op(\'del\',\'' + val + '\',\'radio-{{time()}}\')" class="Hui-iconfont">&#xe6e2;</i>\n' +
                                    '                                </div>'
                                $('#ziding').parent('.radio-box').before(str);
                            } else {
                                $('#' + id).parent('.radio-box').remove();
                            }
                        } else {
                            layer.msg(str + '失败');
                        }
                    },
                    error: function (data) {
                        ajax_error(data);
                    },
                    beforeSend: function () {
                        //0.4透明度 白色遮罩
                        index2 = layer.load(2, {shade: [0.05, '#000']});
                    },
                    complete: function () {
                        layer.close(index2);
                    },
                });
            }
        }

        function check() {
            $(':input[type=radio]', '#place').removeAttr('checked');
            $('#ziding').trigger('click');
        }

        function imgdel(bar_code, e) {
            $.ajax({
                type: 'get',
                url: '/{{config('constant.name_admin')}}/sampleinfo/imgdeal/photo/del/' + bar_code,
                success: function (data) {
                    if (data === '1') {
                        $(e).parent().html('');
                        $('#ImgConDiv').html('');
                        layer.msg('删除成功!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('删除失败!', {icon: 2, time: 2000});
                    }
                },
                error: function (data) {
                    ajax_error(data);
                },
                beforeSend: function () {
                    //0.4透明度 白色遮罩
                    index2 = layer.load(2, {shade: [0.05, '#000']});
                },
                complete: function () {
                    layer.close(index2);
                },
            });
        }

        function scanCode() {
            let iswx = is_weixn();
            if (!iswx) {
                layer.msg('仅支持微信端扫码');
                return false;
            }
            $.ajax({
                type: 'post',
                url: '/{{config('constant.name_admin')}}/wxjssdk/getSignPack',
                data: {
                    _token: '{{csrf_token()}}',
                    url: window.location.href,
                },
                success: function (data) {
                    // console.log(data);
                    if (data == 0) {
                        layer.msg('您还没有配置微信端');
                        return false;
                    }
                    let jsApiList = ['scanQRCode'], signPackage = data;
                    wxready(signPackage, jsApiList);
                    wx.scanQRCode({
                        needResult: 1,
                        desc: 'scanCode desc',
                        success: function (res) {
                            //扫码后获取结果参数:htpp://xxx.com/c/?6123，截取到url中的防伪码后，赋值给Input
                            var url = res.resultStr;
                            $('#erweima').val(url);
                            keyenter(url);
                        },
                        error: function (res) {
                            if (res.errMsg.indexOf('function_not_exist') > 0) {
                                layer.msg('版本过低请升级')
                            }
                        }
                    });

                },
                error: function (data) {
                    ajax_error(data);
                },
                beforeSend: function () {
                    //0.4透明度 白色遮罩
                    index2 = layer.load(2, {shade: [0.05, '#000']});
                },
                complete: function () {
                    layer.close(index2);
                },
            });
        }

        function checkAll(obj) {
            resetcheckbox();
            $('input[type="checkbox"]', '#datatb').prop('checked', $(obj).prop("checked"));  //清空所有input框
        }

        function next(e) {
            let next = $('tbody tr:first-child');
            if ($('tbody tr.trChecked').length > 0) {
                next = $('tbody tr.trChecked').next();
            }
            if (next.length === 0) {
                layer.msg('到头啦！');
                return;
            }
            next.trigger('click');
        }

        $('#manufacturer').on('change', function () {
            $("#facturer").select2().val($(this).val());
            if ($("#facturer").select2().val() !== '') {
                $("#facturer").select2().val($(this).val()).trigger("change");
            }
        })
        $('#facturer').on('change', function () {
            $('#manufacturer').val($(this).val());
        })
        $('.myFenList').on('click', function () {
            $(this).css('color', '#5a98de')
            $(this).siblings().css('color', '#000')
            let toolname = $(this).find('.tool-name').text();
            $('input[type=search]').val(toolname);
            var regExSearch = '^' + toolname + '$';
            table.column(4).search(regExSearch, true, false).draw();
        })
    </script>
@endsection
